/*! \file ffdecoder.h
*/
#pragma once

extern "C"
{
#include "avcodec.h"
#include "avformat.h"
}

#include <string>
using namespace std;


//! A class to implement ffmpeg function
/*!
This is the first version 
\author axboris@gmail.com
\date [12/26/2006]
*/
class CFFDecoder
{
public:
	CFFDecoder(void);
	~CFFDecoder(void);

public:
	 //! set the input media file name
	 /*! 
	 *\param szFileName, the input file name
	 *\return return ff_ok if success, or fferr_xx if fail.
	 *	
	 *\sa OutPut
	 */
	int PutMedia(const char* szFileName);
	
	//! set output file name
	/*!
	*\param filename, the output file name
	*\param overwrite, if true, will write the file no prompt
	*\return ff_ok if success, or fferr_xx if fail.
	*	
	*\sa PutMedia
	*/
	int OutPut(const char* filename, bool overwrite = true);

	//!the main part to transcode
	/*!
	 *\param
	 *\return ff_ok if success, or fferr_xx if fail.
	 *	
	 *\sa PutMedia OutPut
	*/
	int FFEncode();


	int DecodeFile(char* file);
	void Test();

private:
	int newAudioStream(AVFormatContext* oc);
	int newVideoStream(AVFormatContext* oc);
#define  MAX_FILES  (20)
private:
    //only one output file
	AVFormatContext* m_pOC;
	AVFormatContext* m_pIC;
	AVFormatContext* m_vInputFiles[MAX_FILES];
	int64_t m_vInputFilesTsOffset[MAX_FILES];
	int m_nNBInputFiles;
	AVFormatContext* m_vOutputFiles[MAX_FILES];
	int m_nNBOutputFiles;
	// map and meta var not define now.
	
	
	AVInputFormat* m_pIFileFormat; 
	AVOutputFormat* m_pOFileFormat;
	AVImageFormat* m_pImageFormat;
		
	int m_nFrameWidth;
	int m_nFrameHeight;
	float m_fFrameAspectRatio;
	enum PixelFormat m_FramePixFmt;
	int m_nFramePadTop;
	int m_nFramePadButtom;
	int m_nFramePadLeft;
	int m_nFramePadRight;
	int m_arrPadColor[3];
	int m_nFrameTopBand;
	int m_nFrameButtomBand;
	int m_nFrameLeftBand;
	int m_nFrameRightBand;
	int m_nArrMaxFrames[4];
    int m_nFrameRate;	
	int m_nFrameRateBase;
	int m_nVideoBitRate;
	int m_nVideoBitRateTolerance;
	float m_fVideoQscale;

	int m_nVideoQMin;
	int m_nVideoQMax;
	int m_nVideoLMin;
	int m_nVideoLMax;
	int m_nVideoMbLMin;
	int m_nVideoMbLmax;
	int m_nVideoQdiff;
	float m_fVideoQblur;
	float m_fVideoQsquish;
	float m_fVideoQcomp;
	uint16_t* m_pIntraMatrix;
	uint16_t* m_pInterMatirx;

	char* m_szVideoRcOverrideString;
	char* m_szVideoRcEq;
	int m_nVideoRcBufferSize;
	float m_fVideoRcBufferAggressivity;
	int m_nVideoRcMaxRate;
	int m_nVideoRcMinRate;
	float m_fVideoRcInitialCplx;
	float m_fVideoBQfactor;
	float m_fVideoBQoffset;
	float m_fVideoIQfactor;
	float m_fVideoIQoffset;
	int m_nVideoIntraQuantBias;
	int m_nvideoInterQuantBias;
	int m_nMeMethod;
	bool m_bVideoDisable;
	bool m_bVideoDiscard;
	CodecID m_videoCodecID;
	//
	bool m_bSameQuality;	
	int m_nBFrames;
	int m_nPreME;
	int m_nDoDeinterlace;
	int m_nWorkAroundBugs;
	int m_nPacketSize;
	int m_nErrorRate;
	int m_nStrict;
	int m_nTopFieldFirst;
	int m_nScThreshold;
	int m_nMeThreshold;
	int m_nMbThreshold;
	int m_nIntraDcPreision;
	int m_nMePenaltyCompsensation;
	int m_nFrameSkipThreshold;
	int m_nFrameSkipFactor;
	int m_nFrameSkipExp;
	int m_nLoopOutput;
	bool m_bGenpts;
	int m_nQpHist;
	int m_nGopSize;
	bool m_bIntraOnly;
	int m_nAudioSampleRate;
	int m_nAudioBitRate;
	float m_fAudioQscale;
	int m_nAudioChannels;	
	//
	char* m_szAudioLang;	
	//
	
	bool m_bVideoStreamCopy;
	bool m_bAudioStreamCopy;	
	CodecID m_audioCodecID;
	
	CodecID m_nSubtitleCodecID;
	char* m_szSubtitleLang;

	int m_nMuxRate;
	int m_nMuxPacketSize;
	float m_fMuxPreload;
	float m_fMuxMaxDelay;

	int64_t m_nRecordTime;
	int64_t m_n64StartTime;
	int64_t m_nRecTimeStamp;
	int64_t m_nInputTsOffset;
	int m_nFileOverWrite;
	char* m_szTitle;
	char* m_szAuthor;
	char* m_szCopyRight;
	char* m_szComment;
	int m_nDoBenchMark;
	int m_nDoHexDump;
	int m_nDoPktDump;
	int m_nDoPSNR;
	int m_nDoVstats;
	int m_nDoPass;
	char* m_szPassLogFileName;

	bool m_bSubtitleStreamCopy;

	int m_nVideoSyncMethod;
	int m_nAudioSyncMethod;
	int m_nCopyTS;
	int m_nOptShortest;
	int m_nVideoGlobalHeader;
	int m_nRateEmu;	
	char* m_szVideoGrabFormat;

	char* m_szVideoDevice;
	char* m_szGrabDevice;

	int m_nVideoChannels;
	char* m_szVideoStandard;

	char* m_szAudioGrabFormat;
	char* m_szAudioDevice;
	int m_nAudioVolume;

	int m_nUsingStdin;
	int m_nUsingVhook;
	int m_nVerbose;
	int m_nThreadCount;
	int m_nQPressed;
	int m_nMeRange;
	int64_t m_nVideoSize;
	int64_t m_nAudioSize;
	int64_t m_nExtraSize;
	int m_nNbFramesDup;
	int m_nNbFramesDrop;
	int m_nInputSync;
	int m_nLimitFileSize;

	int m_nPgmyuvCompatibiltyHack;
	int m_nDtsDeltaThreshold;
	char** m_szOptName;
	int m_nOptNameCount;
	AVCodecContext* m_pAvctxOpts;

private:
	string m_infile;
	string m_outfile;
};
